'''
Created on Mar 12, 2012

@author: wilshusensk
'''

from java.lang import System, Class, ClassNotFoundException
from java.sql import DriverManager, SQLException
import sys

try:
    System.setProperty("sqlite.purejava", "true") # Strictly optional; use if you get UnsatisfiedLinkError or the like.
    Class.forName("org.sqlite.JDBC")
    con = DriverManager.getConnection("jdbc:sqlite:testdb")
    stat = con.createStatement()
except ClassNotFoundException, e:
    sys.exit(e.message)
except SQLException, e:
    sys.exit(e.message)    

done = False
while not done:
    cmd = raw_input("Enter command: ")
    if cmd == 'quit':
        done = True
    else:
        if stat.execute(cmd):
            print("\nCommand is:  ")
            print(cmd)
            columns = input("Enter number of columns expected:")
            results = stat.getResultSet()
            while results.next():
                for c in range(1, columns + 1):
                    print results.getString(c), '\t',
                print
